package com.ruoyi.api.worker;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.JiajiaWorker;
import com.ruoyi.system.domain.JiajiaZiZhi;
import com.ruoyi.system.service.IJiajiaWorkerService;
import com.ruoyi.system.service.IJiajiaZiZhiService;
import com.ruoyi.system.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/api/worker/zizhi")
@Api(tags = "社工端资质认证相关接口")
public class ApiWorkerZiZhiController {


    @Autowired
    private IJiajiaZiZhiService ziZhiService;

    @Autowired
    private IJiajiaWorkerService workerService;

    @ApiOperation("新增资质证件")
    @PostMapping("/addZiZhi")
    public AjaxResult submitZiZhi(@RequestParam String urls){

        JiajiaWorker worker = workerService.selectJiajiaWorkerById(TokenUtil.getUid());
        if (worker == null) return AjaxResult.notLogin();

        JiajiaZiZhi ziZhi = new JiajiaZiZhi();
        ziZhi.setUrl(urls);
        ziZhi.setWid(worker.getId());
        ziZhiService.insertJiajiaZiZhi(ziZhi);

        return AjaxResult.success("添加成功");
    }

    @ApiOperation("获取资质证件")
    @PostMapping("/getZiZhiList")
    public AjaxResult getZiZhiList(){
        JiajiaWorker worker = workerService.selectJiajiaWorkerById(TokenUtil.getUid());
        if (worker == null) return AjaxResult.notLogin();

        JiajiaZiZhi ziZhi = new JiajiaZiZhi();
        ziZhi.setWid(worker.getId());
        List<JiajiaZiZhi> ziZhiList = ziZhiService.selectJiajiaZiZhiList(ziZhi);

        return AjaxResult.success(ziZhiList);
    }

    @ApiOperation("删除资质证件")
    @PostMapping("/delZiZhi")
    public AjaxResult delZiZhi(@RequestParam Long id){
        ziZhiService.deleteJiajiaZiZhiByIds(id+"");
        return AjaxResult.success("删除成功");
    }

}
